#!/usr/bin/python
# -*- coding: UTF-8 -*-
#cron:6 6,8,10 * * *
import json
import time
import random
import requests
import base64
import os
import sys
token=os.environ.get('hipc_token')
contents=[]
cishu = 0
# 加载通知服务
def load_send():
    cur_path = os.path.abspath(os.path.dirname(__file__))
    sys.path.append(cur_path)
    if os.path.exists(cur_path + "/notify2.py"):
        try:
            from notify2 import send
            return send
        except Exception as e:
            print(f"加载通知服务失败：{e}")
            return None
    else:
        print("加载通知服务失败")
        return None

#laxin

def laxin():
       headers = {
        'content-length':'27',
        'user-id':'41222',
        'xweb_xhr':'1',
        'platform':'miniprogram_windows',
        'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11437',
        'app':'hipc',
        'token':token,
        'content-type':'application/json',
        'accept':'*/*',
        'sec-fetch-site':'cross-site',
        'sec-fetch-mode':'cors',
        'sec-fetch-dest':'empty',
        'referer':'https://servicewechat.com/wx6265a35adb332603/180/page-frame.html',
        'accept-encoding':'gzip, deflate, br',
        'accept-language':'zh-CN,zh;q=0.9'}
       payload=base64.b64decode("eyJib251c19rZXkiOiAibGF4aW4ifQ==")
       #data = {"bonus_key":"advertising"}


       response0 = requests.request("POST", "https://api.hipcapi.com/v1/scorebonus/finish", headers=headers, data=payload)
       print(response0.text)
       content = response0.json()["message"]
       return content

while cishu<33:
  number = random.randint(50,300)
  print(f'延迟{number}后继续')
  time.sleep(number)
  cishu = cishu +1
  content = f'第{cishu}次执行结果：{laxin()}\n'
  contents.append(content)
  print(f'已执行第{cishu}次')

# 将编码结果字典转换为JSON字符串
#data = json.dumps(encoded_results)
contents_str = "".join(contents)
#print(data)
print(contents_str)
title = "HIPC拉新任务通知"
contents = contents_str
send_notify = load_send()
send_notify(title, contents)
# 将编码结果字典转换为JSON字符串
#data = json.dumps(encoded_results)

#print(data)